<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    #commentForm .main-container{padding-bottom: 50px!important;}
    .main-container{padding-top: 10px!important;}
    .add-tag{margin: 5px 0}
    .mainBox{bottom: 0!important;}
    .xuanmsg{color: #aaa;margin: -11px 0 5px 11px;font-size: 12px}
    .page-title{border-bottom: 10px solid #ecf0f1;}
    .bottss{width: 100%;height: 30px;position: fixed;bottom: 0;}
    .tes_label{width: 146px!important;}
    body{overflow-x: hidden}
</style>
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title">
        <div class="page-title-con"><span>加签</span><div class="move_title"></div><?php include "../public/sub.php";?></div>
    </div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text style="color: red">*</text>加签给</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=adder&type=user&single=2');"></div>
                                <div class="tanxiannei" id="adder"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=adder&type=user&single=2');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="adder_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <div class="layui-input-block" >
                            <div class="radio-block" style="height: 70px!important;">
                                <input type="radio" name="addtype" lay-filter="addtype" checked value="1" title="同意并加签">
                                <input type="radio" name="addtype" lay-filter="addtype" value="2" title="直接加签">
                                <div class="xuanmsg" id="addtypemsg">审核同意的同时，请被加签人参与审核。</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <div class="layui-input-block">
                            <div class="radio-block" style="height: 70px!important;">
                                <input type="radio" name="addcate" lay-filter="addcate" checked value="1" title="被加签人会签">
                                <input type="radio" name="addcate" lay-filter="addcate" value="2" title="被加签人或签">
                                <input type="radio" name="addcate" lay-filter="addcate" value="3" title="被加签人依次审批">
                                <div class="xuanmsg" id="addcatemsg">所选被加签人需全部审核。</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12 tes_box">
                        <label class="layui-form-label" style="border-color: #F2F2F2!important;">处理意见</label>
                        <div class="layui-input-block tes_block" style="margin-left:0 !important;width: calc(100% - 180px)!important;min-height: 120px;height: auto">
                            <input type="hidden" name="agree" value="1">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                            <!--                            <input type="text" name="explain" id="explain" placeholder="请输入" clearable  autocomplete="off" class="layui-input">-->
                            <span style="color: #1ca5ff;cursor: pointer;float: left;padding-left: 5px;padding-top:4px" class="add-tag" onclick="addFlowUsed()">加入常用说明</span>
                            <div class="tag-box" id="flow_used_div" style="float: left;padding-left: 5px"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="qianshen">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label" style="height: 98px;line-height: 84px"><text>*</text>手写签名</label>
                        <div class="layui-input-block signshen">
                            <div class="deaqian deadea" onclick="openPage('flow_signshen.php')">
                                <span class="iico"><i class="layui-icon layui-icon-edit"></i></span>
                                <span class="qiantxt">点此签名</span>
                            </div>
                            <div class="deaqian deazhen layui-hide">
                                <img src="">
                                <i class="layui-icon layui-icon-close iiclose" onclick="delQian()"></i>
                                <input type="hidden" id="qian_id" name="qian_id">
                                <input type="hidden" id="qian" name="qian">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfotwo.php'?>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">抄送</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=promer&type=user&single=2');"></div>
                                <div class="tanxiannei" id="promer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=promer&type=user&single=2');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>
<div class="bottss"></div>
<script>
    var param_id = getQueryVariable('id') || 0;
    var param_isqian = getQueryVariable('isqian') || 0;
    if(param_isqian == 1){
        $("#qianshen").removeClass('layui-hide');
    }
    function delQian (){
        $(".signshen .deadea" ).removeClass('layui-hide');
        $(".signshen .deazhen").addClass('layui-hide');
        $(".signshen .deazhen img").attr('src', '');
        $("#qian_id").val('');
        $("#qian").val('');
    }

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;

        public_upload_file_load('upload_files');

        facade.ajax({url: ask_opt_get_flow_used}).done(function(res){
            if (res.code === 2000) {
                show_flow_used(res.data.used);
                var qianinfo = res.data.qianinfo;
                if(param_isqian == 1 && qianinfo){
                    $("#qian_id").val(qianinfo.qian_id);
                    $("#qian").val(qianinfo.qian);
                    $(".signshen .deadea").addClass('layui-hide');
                    $(".signshen .deazhen").removeClass('layui-hide');
                    $(".signshen .deazhen img").attr('src', get_file_complete(qianinfo.qian));
                }
                render_from();
            }
        });

        form.on('radio(addtype)',function (data) {
            if(data.value == 1){
                $("#addtypemsg").text('审核同意的同时，请被加签人参与审核。');
            }else{
                $("#addtypemsg").text('我暂不审，由被加签人审核完成（同意）后，单据再度回到我这里处理。');
            }
        });

        form.on('radio(addcate)',function (data) {
            if(data.value == 1){
                $("#addcatemsg").text('所选被加签人需全部审核');
            }else if(data.value == 2){
                $("#addcatemsg").text('所选被加签人其中一人审核即可');
            }else{
                $("#addcatemsg").text('所选被加签人按以上顺序依次全部审批');
            }
        });

        form.on('submit(add)', function(data){
            data.field.adder = tan_tags_getvalue("#adder", 'user');

            var validRes = true;
            if(!data.field.adder){
                $("#adder").parents('.tanxian').addClass('tanerror');
                $('#adder_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#adder").parents('.tanxian').removeClass('tanerror');
                $('#adder_tanerror').text('');
            }
            if(!validRes){return false;}

            data.field.id = param_id;
            data.field.ispc = 1;
            data.field.promer = tan_tags_getvalue("#promer", 'user');
            data.field.files = public_upload_file_value_str('upload_files');

            facade.ajax({url: ask_flow_examine_bill, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    facade.success('操作成功');
                    setTimeout(function () {
                        parent.window.location.reload();
                    },1500);
                }
            });

            return false;
        });
    });








    function show_flow_used(data) {
        var str = '';
        for (var key in data){
            str += '<div class="tag-box-div">';
            str += '<span class="tag-name" onclick="pushFlowUsed(this)">'+data[key].explain+'</span>';
            str += '<span class="tag-close" onclick="delFlowUsed('+data[key].id+')">×</span>';
            str += '</div>';
        }
        $("#flow_used_div").html(str);
    }

    function addFlowUsed() {
        var explain = $('#explain').val() || '';
        if(!explain){
            facade.error('请填写处理意见');return false;
        }
        layui.use(['laytp', 'form'], function() {
            var form = layui.form, layer = layui.layer;
            facade.ajax({url: ask_opt_add_flow_used, data:{explain:explain}}).done(function(res){
                if (res.code === 2000) {
                    show_flow_used(res.data);
                    render_from();
                }
            });
        });
    }

    function pushFlowUsed(obj){
        var value = $(obj).text();
        var explain = $('#explain').val();
        $('#explain').val(value);
    }

    function delFlowUsed(id){
        layui.use(['laytp', 'form'], function() {
            var form = layui.form, layer = layui.layer;

            facade.ajax({url: ask_opt_del_flow_used, data:{id:id}}).done(function(res){
                if (res.code === 2000) {
                    show_flow_used(res.data);
                    render_from();
                }
            });
        });
    }

</script>
</body>
</html>
